package com.unohacha.qqj.fzdr.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.unohacha.qqj.fzdr.FindImageByImageActivity;
import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.mylibrary.base.BaseFragment;
import com.unohacha.qqj.mylibrary.view.MyGridView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class PublicImageFragment extends BaseFragment {
    @BindView(R.id.public_image_grid)
    MyGridView publicImageGrid;
    @BindView(R.id.image_commit)
    Button imageCommit;
    Unbinder unbinder;

    @Override
    protected void initBundle(Bundle arguments) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_public_image_layout;
    }

    @Override
    protected void initView(View rootView) {
        publicImageGrid.setAdapter(new MyAdapter());
    }

    @Override
    protected void initData() {

    }
    private int images[] = {R.mipmap.a, R.mipmap.b, R.mipmap.c, R.mipmap.d};
    private String[] strings = {"针织面料", "素色面料", "提花面料", "其他"};

    @OnClick({R.id.public_image_grid, R.id.image_commit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.public_image_grid:
                break;
            case R.id.image_commit:
                break;
        }
    }

    class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return strings.length;
        }


        @Override
        public Object getItem(int position) {
            return strings[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View view, ViewGroup viewGroup) {
            //将布局文件转换成View
            View gridview_item = View.inflate(getContext(), R.layout.activity_find_image_by_image_grid_item, null);
            ImageView iv_icon = gridview_item.findViewById(R.id.image_grid_item_image);
            TextView tv_title = gridview_item.findViewById(R.id.image_grid_item_text);
            iv_icon.setBackgroundResource(images[position]);
            tv_title.setText(strings[position]);
            return gridview_item;
        }


    }
}
